/* eslint-disable jsdoc/no-restricted-syntax */
const delayArr = [1, 2, 3, 4, 5, 6, 7, 8];

/**
 * @param {number[]} arr
 * @param {number} init
 * @returns {[number, ...number[]]}
 */
function prefixSum(arr, init = 0) {
  return arr.reduce(
    /**
     * @param {[number, ...number[]]} prev
     * @param {number} cur
     * @returns {[number, ...number[]]}
     */
    (prev, cur) => [...prev, cur + /** @type {*} */ (prev.at(-1))],
    /** @type {[number]} */ ([init]),
  );
}
console.log("prefixSum", prefixSum(delayArr));
/**
 * @name reducer
 * @param {number[]} arr
 * @returns {number[]}
 */
function suffixSum(arr) {
  return arr.reduceRight(
    (prev, cur) => [cur + prev[0], ...prev],
    /** @type {number[]} */ ([0]),
  );
}
console.log("suffixSum", suffixSum(delayArr));
